//
//  WDDProductFlipView.m
//  SZBank
//
//  Created by rimi on 16/7/15.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "WDDProductFlipView.h"
#import "LocalDataManager.h"
#import "NSString+SizeOfString.h"
#import "WDDImageScrollView.h"
#import "NSString+SizeOfString.h"

#define THEMECOLOR [UIColor colorWithPatternImage:[LocalDataManager getImageWithSourceOfPath:@"贵金属详情_03"]]
@interface WDDProductFlipView()

/**  弹框视图 */
@property (nonatomic,strong) UIImageView *flipImageView;
@property (nonatomic,strong) UIImageView *bgImage;
@property (nonatomic,strong) WDDImageScrollView *imageScroll;
@end
@implementation WDDProductFlipView
{
    CGFloat frameWidth;/**  自身宽度 */
    CGFloat frameHeight;/**  自身高度 */
}

- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        frameWidth = self.frame.size.width;
        frameHeight = self.frame.size.height;
        self.alpha = 1;
        UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(frameWidth * 0.86, frameHeight * 0.87, 140, 60)];
        [backButton setImage:[LocalDataManager getImageWithSourceOfPath:@"贵金属详情_关闭"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(action_backButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.flipImageView];
        [self addSubview:backButton];
        [self addSubview:self.productImage];
        
        
        
    }
    return self;
}

- (void)action_backButton{
    /**  弹出动画 */
    [UIView animateWithDuration:0.8 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        
    }];
}

- (void)productReudce{
    /**  标题 */
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frameWidth * 0.4, 40)];
    title.font = [UIFont systemFontOfSize:22];
    title.backgroundColor = [UIColor clearColor];
    title.textAlignment = NSTextAlignmentCenter;
    title.text = self.title;
    /**  介绍 */
    UILabel *bgLabel = [[UILabel alloc] init];
    [self getLabel:bgLabel labelFrame:CGRectMake(0, KWIDTH * 0.05, 80, 40) labelText:@"介绍" labelColor:[UIColor whiteColor] labelBgColor:THEMECOLOR];
    /**  介绍内容 */
    NSString *string1 = self.introduceStr;
    CGFloat height1 = [NSString textString:string1 fontSize:23 maxWidth:frameWidth * 0.42].height;
    UILabel *textLabel = [[UILabel alloc] init];
    [self getLabel:textLabel labelFrame:CGRectMake(0, KWIDTH * 0.08, KWIDTH * 0.42, height1) labelText:self.introduceStr labelColor:[UIColor blackColor] labelBgColor:[UIColor clearColor]];
    /**  规格 */
    UILabel *standard = [[UILabel alloc] init];
    [self getLabel:standard labelFrame:CGRectMake(0, CGRectGetMaxY(textLabel.frame), 80, 40) labelText:@"规格" labelColor:[UIColor whiteColor] labelBgColor:THEMECOLOR];
    /**  规格内容 */
    UILabel *quality = [[UILabel alloc] init];
    [self getLabel:quality labelFrame:CGRectMake(frameWidth * 0.01, CGRectGetMaxY(textLabel.frame), 300, 40) labelText:[NSString stringWithFormat:@"%@%@",@"成色：",self.qualityStr] labelColor:[UIColor blackColor] labelBgColor:[UIColor clearColor]];
    UILabel *numbers = [[UILabel alloc] init];
    [self getLabel:numbers labelFrame:CGRectMake(frameWidth * 0.05, CGRectGetMaxY(textLabel.frame) + 50, 300, 40) labelText:[NSString stringWithFormat:@"%@%@",@"规格/枚套：",self.numbersStr] labelColor:[UIColor blackColor] labelBgColor:[UIColor clearColor]];
    UILabel *weight = [[UILabel alloc] init];
    [self getLabel:weight labelFrame:CGRectMake(frameWidth * 0.05, CGRectGetMaxY(textLabel.frame) + 100, 300, 40) labelText:[NSString stringWithFormat:@"%@%@",@"克重(g)：",self.weightStr] labelColor:[UIColor blackColor] labelBgColor:[UIColor clearColor]];
    UILabel *price = [[UILabel alloc] init];
    [self getLabel:price labelFrame:CGRectMake(frameWidth * 0.05, CGRectGetMaxY(textLabel.frame) + 150, 300, 40) labelText:[NSString stringWithFormat:@"%@%@",@"价格：",self.priceStr] labelColor:[UIColor blackColor] labelBgColor:[UIColor clearColor]];
    /**  文档 */
    UILabel *document = [[UILabel alloc] init];
    [self getLabel:document labelFrame:CGRectMake(0, CGRectGetMaxY(price.frame), 80, 40) labelText:@"文档" labelColor:[UIColor whiteColor] labelBgColor:THEMECOLOR];
    NSArray *array = @[@"说明书",@"条款",@"宣传资料"];
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(frameWidth * 0.55, frameHeight * 0.15, frameWidth * 0.42, frameHeight * 0.7)];
    self.scrollView.contentSize = CGSizeMake(frameWidth * 0.42, height1 + 450);
    self.scrollView.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.bgImage];
    [self addSubview:self.scrollView];
    /**  文档内容 */
    for (int i = 0; i < array.count; i ++){
        UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(frameWidth * 0.06, CGRectGetMaxY(price.frame) + i * frameHeight * 0.05, frameWidth * 0.1, frameHeight * 0.03)];
        button.backgroundColor = [UIColor clearColor];
        button.titleLabel.font = [UIFont systemFontOfSize:23];
        [button setTitleColor:THEMECOLOR forState:UIControlStateNormal];
        [button setTitle:array[i] forState:UIControlStateNormal];
        [self.scrollView addSubview:button];
    }
    [self.scrollView addSubview:title];
    [self.scrollView addSubview:bgLabel];
    [self.scrollView addSubview:textLabel];
    [self.scrollView addSubview:standard];
    [self.scrollView addSubview:quality];
    [self.scrollView addSubview:numbers];
    [self.scrollView addSubview:weight];
    [self.scrollView addSubview:price];
    [self.scrollView addSubview:document];
}

- (void)getLabel:(UILabel *)label labelFrame:(CGRect)labelFrame labelText:(NSString *)labelText labelColor:(UIColor *)labelColor labelBgColor:(UIColor *)labelBgColor{
    label.frame = labelFrame;
    label.text = labelText;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = labelColor;
    label.backgroundColor = labelBgColor;
    label.font = [UIFont systemFontOfSize:23];
    label.numberOfLines = 0;
}

- (void)action_imageClick{
    self.imageScroll.data = self.sourceArray;
    [self.imageScroll initUserInterface];
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:self.imageScroll];
}

- (UIImageView *)flipImageView{
    if (!_flipImageView) {
        _flipImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frameHeight * 0.1, frameWidth, frameHeight * 0.88)];
        _flipImageView.image = [LocalDataManager getImageWithSourceOfPath:@"贵金属详情_01"];
    }
    return _flipImageView;
}

- (UIImageView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frameWidth * 0.42, 40)];
        _bgImage.image = [LocalDataManager getImageWithSourceOfPath:@"贵金属详情_03"];
    }
    return _bgImage;
}

- (UIImageView *)productImage{
    if (!_productImage) {
        _productImage = [[UIImageView alloc] initWithFrame:CGRectMake(frameWidth * 0.05, frameHeight * 0.2, frameWidth * 0.45, frameHeight * 0.6)];
        _productImage.contentMode = UIViewContentModeScaleAspectFit;
        _productImage.backgroundColor = [UIColor clearColor];
        _productImage.userInteractionEnabled = YES;
        UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_imageClick)];
        [_productImage addGestureRecognizer:imageTap];
    }
    return _productImage;
}

- (WDDImageScrollView *)imageScroll{
    if (!_imageScroll) {
        _imageScroll = [[WDDImageScrollView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT)];
    }
    return _imageScroll;
}
@end
